<?php
class Soctypesrel extends AppModel {

	var $name = 'Soctypesrel';
	var $useDbConfig = 'socdual';

	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $belongsTo = array(
			'Soctype' => array('className' => 'Soctype',
								'foreignKey' => 'soctype_id',
								'conditions' => '',
								'fields' => '',
								'order' => ''
			),
			'Extsoctype' => array('className' => 'Soctype',
								'foreignKey' => 'extsoctype_id',
								'conditions' => '',
								'fields' => '',
								'order' => ''
			),
			'Socrelation' => array('className' => 'Socrelation',
								'foreignKey' => 'socrelation_id',
								'conditions' => '',
								'fields' => '',
								'order' => ''
			)
	);

	function getTypesRelations() {
		return $this->find('all');
	}

	function getTypeRelations($id, $relCond = array()) {
		$this->unBindModel(array('belongsTo'=>array('Soctype')));
		$f = array('Extsoctype.id', 'Socrelation.percent');

		$c = array('Soctypesrel.soctype_id'=>$id);
		$c = array_merge($relCond, $c);
		$data = $this->find('all', array('conditions'=>$c, 'fields'=>$f));

		return array_combine(Set::extract($data, '{n}.Extsoctype.id'), Set::extract($data, '{n}.Socrelation.percent'));
	}
	
	function getRelationByTypes($id, $sid) {
		$conditions = array('soctype_id'=>$id, 'extsoctype_id'=>$sid);
		$res = $this->find('all', array('conditions'=>$conditions));
		pr($res);
	}

}
?>
